const http = require('http');

let server = http.createServer();

server.on('request', (req, res) => {
  switch (req.url) {
    case '/':
      res.end(
        JSON.stringify({
          msg: 'home'
        })
      )
      break;
    case '/data':
      res.end(
        JSON.stringify({
          msg: 'hello',
          code: 100
        })
      )
      break;
    case '/list':
      res.end(
        JSON.stringify({
          msg: 'list',
          info: '666'
        })
      )
      break;
  
    default:
      break;
  }
})

server.listen(8080, '127.0.0.1', () => {
  console.log(`服务已启动，正在监听8080端口`);
})